package com.jstyle.jclifexd.daoManager;

import android.text.TextUtils;

import com.jstyle.jclifexd.dao.BodyFatDataDao;
import com.jstyle.jclifexd.dao.HealthDataDao;
import com.jstyle.jclifexd.model.BodyFatData;
import com.jstyle.jclifexd.model.HealthData;
import com.jstyle.jclifexd.utils.DbManager;
import com.jstyle.jclifexd.utils.SharedPreferenceUtils;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.ArrayList;
import java.util.List;

public class BodyFatDaoManager{
    public static void insertData(List<BodyFatData> stepDataList){
        DbManager.getInstance().getDaoSession().getBodyFatDataDao().insertOrReplaceInTx(stepDataList);
    }

    public static List<BodyFatData> queryData(String queryDate){
        List<BodyFatData>healthDataList=new ArrayList<>();
        String address= SharedPreferenceUtils.getSpString(SharedPreferenceUtils.KEY_ADDRESS);
        if(TextUtils.isEmpty(queryDate)||TextUtils.isEmpty(address))return healthDataList;
        QueryBuilder<BodyFatData> queryBuilder = DbManager.getInstance().getDaoSession().getBodyFatDataDao().queryBuilder();
        healthDataList = queryBuilder.where(BodyFatDataDao.Properties.Address.eq(address), BodyFatDataDao.Properties.Date.between(queryDate+" 00:00:00" , queryDate+" 23:59:59")).orderDesc(BodyFatDataDao.Properties.Date).list();
        return healthDataList;
    }
}
